package com.zhisheng.gufei.produce.dao.impl;


import java.util.ArrayList;
import java.util.List;

import org.springframework.stereotype.Repository;

import com.zhisheng.core.dao.impl.BaseDaoHibernate;
import com.zhisheng.gufei.city.entity.City;
import com.zhisheng.gufei.grabagesort.entity.GrabageSort;
import com.zhisheng.gufei.produce.dao.GrabageProduceDestInfoDao;
import com.zhisheng.gufei.produce.entity.GrabageProduceDestInfo;

/**
 * @author xgye
 * @date 2009-9-12
 * @version $Id$
 */
@Repository("grabageProduceDestInfoDao")
@SuppressWarnings("unchecked")
public class GrabageProduceDestInfoDaoHibernate extends BaseDaoHibernate<GrabageProduceDestInfo, Integer> 
                           implements GrabageProduceDestInfoDao {

    public List<GrabageProduceDestInfo> getPDListByGFList(List<GrabageSort> gfList) {
        List<GrabageProduceDestInfo> infoList = new ArrayList<GrabageProduceDestInfo>();
        
        for (GrabageSort sort : gfList) {
            List<GrabageProduceDestInfo> tmpResult = getHibernateTemplate()
                        .find("from GrabageProduceDestInfo info where info.grabage.code = '" + sort.getCode() + "' and info.corperation.needStat = 1");
            if (tmpResult != null) {
                infoList.addAll(tmpResult);
            }
        }
        
        return infoList;
    }
    
    
    public List<GrabageProduceDestInfo> getPDListByCity(List<City> cityList) {
        List<GrabageProduceDestInfo> infoList = new ArrayList<GrabageProduceDestInfo>();
        
        for (City city : cityList) {
            List<GrabageProduceDestInfo> tmpResult = getHibernateTemplate()
                        .find("from GrabageProduceDestInfo info where info.corperation.areaCode = '" + city.getId() + "' and info.corperation.needStat = 1");
            
            if (tmpResult != null) {
                infoList.addAll(tmpResult);
            }
        }
        
        return infoList;
    }


}
